package com.cqcj.login.web;

import com.cqcj.login.pojo.Brand;
import com.cqcj.login.service.BrandService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/addBrandServlet")
public class AddBrandServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        BrandService brandService = new BrandService();
        Brand brand = new Brand();
        brand.setBrandname(request.getParameter("brandname"));
        brand.setCompanyname(request.getParameter("companyname"));
        brand.setOrdered(Integer.valueOf(request.getParameter("ordered")));
        brand.setDescription(request.getParameter("description"));
        brand.setStatus(request.getParameter("status"));
        System.out.println(brand);

        int flag = brandService.insetBrand(brand);
        System.out.println(flag);
        if(flag >0) {
            System.out.println("增加品牌成功");
            String contextPath = request.getContextPath();
            response.sendRedirect(contextPath + "/selectBrandAllServlet");
        }
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }


}
